<%-- 
    Document   : purchaseForm
    Created on : 14/04/2009, 09:59:21 AM
    Author     : Joel Chuca
--%>

<%@ include file="/common/taglibs.jsp"%>

<head>
    <title><fmt:message key="purchaseDetail.title"/></title>
    <meta name="heading" content="<fmt:message key='purchaseDetail.heading'/>"/>
     <meta name="menu" content="RolePurchaser"/>
    <!--link rel="stylesheet" type="text/css" media="all" href="styles/calendar-aqua/theme.css" /-->

    <script type="text/javascript" src="<c:url value='/scripts/calendar/calendar.js'/>"></script>
    <script type="text/javascript" src="<c:url value='/scripts/calendar/lang/calendar-es.js'/>"></script>
    <script type="text/javascript" src="<c:url value='/scripts/calendar/calendar-setup.js'/>"></script>
                                       
    <script type="text/javascript">
        window.onload = function() {
            Calendar.setup({
                inputField: "dateMakeID",
                ifFormat: "%d/%m/%Y",
                button: "dateMakeID"
            });

            Calendar.setup({
                inputField: "dateCreditID",
                ifFormat: "%d/%m/%Y",
                button: "dateCreditID"
            });
        }

        function modifyStateDiscount(){
            if(document.getElementById("withDiscount").checked){
                document.getElementById("discount").disabled =false;
            }
            else{
                document.getElementById("discount").value="";
                document.getElementById("discount").disabled=true;

            }
        }
        function modifyStateBill(){
            if(document.getElementById("withBill").checked)
                document.getElementById("codeBill").disabled =false;
            else{
                document.getElementById("codeBill").value="";
                document.getElementById("codeBill").disabled=true;
            }
        }
        function modifyStateCredit(){
            if(document.getElementById("withCredit").checked)
                document.getElementById("dateCreditID").disabled =false;
            else{
                document.getElementById("dateCreditID").value="";
                document.getElementById("dateCreditID").disabled=true;
            }
        }
    </script>
</head>
<div id="help">
    <h2>
        <a href="<c:url value='helpMaterialPurchase.html?decorate=false'/>"
           title="Ayuda Formulario de Compra de Materia Prima"
           onclick="Modalbox.show(this.href, {title: this.title, width: 600}); return false;">
               <fmt:message key="help"/>
        </a>
    </h2>
</div>
<s:form id="purchaseForm" action="savePurchase" method="post" validate="true">
    <s:hidden key="purchase.id" cssClass="text medium"/>
    <table border="0">
        <tbody><tr>
                <c:if test="${ empty purchase.id  || purchase.deleted}">
                    <td>
                        <s:textfield key="dateMake" id="dateMakeID" required="true" cssClass="text medium"/>
                    </td>
                    <td>
                        <s:select key="suppliers" list="suppliers" name="purchase.supplier.id" listKey="id" listValue="fullName"
                                  headerKey="-1" headerValue="-- Seleccione --" />
                    </td>
                    <td>
                        <s:select key="coins" list="coins" name="purchase.coin.id" listKey="id" listValue='name'
                                  headerKey="-1" headerValue="select" />
                    </td>
                </c:if>
                
                <c:if test="${ (not empty purchase.id) && !purchase.deleted }">
                    <td>
                        <s:textfield key="dateMake" id="dateMakeID" required="true" cssClass="text medium" disabled="true"/>
                        <s:hidden name="dateMake" value="%{dateMake}"/>
                    </td>
                    <td>
                        <s:select key="suppliers" list="suppliers" name="purchase.supplier.id" listKey="id" listValue="fullName"
                                  headerKey="-1" headerValue="-- Seleccione --" disabled="true"/>
                        <s:hidden name="purchase.supplier.id" value="%{purchase.supplier.id}"/>
                    </td>
                    <td>
                        <s:select key="coins" list="coins" name="purchase.coin.id" listKey="id" listValue='name'
                                  headerKey="-1" headerValue="select" disabled="true"/>
                        <s:hidden name="purchase.coin.id" value="%{purchase.coin.id}"/>
                    </td>
                </c:if>

        </tr></tbody>
    </table>

    <table border="0">
        <tbody>
            <tr><td><fieldset>
                        <legend><fmt:message key="purchase.discountSetting"/></legend>
                        <s:checkbox name="withDiscount" id="withDiscount"  onclick="modifyStateDiscount()"/>
                        <label for="withDiscount" class="choice">Con descuento</label>
                        <s:textfield key="purchase.discount" id="discount" required="true" cssClass="text medium" onmousedown="modifyStateDiscount()"/>
                </fieldset></td>
                <td><fieldset>
                        <legend><fmt:message key="purchase.billSetting"/></legend>
                        <s:checkbox name="withBill" id="withBill"  onclick="modifyStateBill()" />
                        <label for="withBill" class="choice">Con factura</label>
                        <s:textfield key="purchase.bill.code" id="codeBill" required="true" cssClass="text medium" onmousemove="modifyStateBill()" />
                </fieldset></td>
                <td><fieldset>
                        <legend><fmt:message key="purchase.creditSetting"/></legend>
                        <s:checkbox name="withCredit" id="withCredit" onclick="modifyStateCredit()"/>
                        <label for="withCredit" class="choice">Con Credito</label>
                        <s:textfield key="dateCredit" id="dateCreditID" required="true" cssClass="text medium" onmouseover="modifyStateCredit()" />
                </fieldset></td>
            </tr>
        </tbody>
    </table>
    
    <li class="buttonBar bottom">
        <s:submit cssClass="button" method="save" key="button.save" theme="simple"/>
        <c:if test="${(not empty purchase.id) && purchase.deleted }">
            <s:submit cssClass="button" method="delete" key="button.delete"
                      onclick="return confirmDelete('material')" theme="simple"/>
        </c:if>
        <c:if test="${(empty purchase.id) || !purchase.deleted }">
            <s:submit cssClass="button" method="delete" key="button.delete"
            onclick="return confirmDelete('material')" theme="simple" disabled="true"/>
        </c:if>
        <s:submit cssClass="button" method="cancel" key="button.cancel" theme="simple"/>
    </li>
</s:form>

<script type="text/javascript">
    Form.focusFirstElement($("materialForm"));
</script>